<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>欢迎登录后台管理系统</title>
<link href="__STATIC__/Admin/css/base.css" rel="stylesheet" type="text/css" />
<link href="__STATIC__/Admin/css/right.css" rel="stylesheet" type="text/css">
<link href="__STATIC__/Admin/css/select.css" rel="stylesheet" type="text/css">

<script src="__STATIC__/js/jquery-2.1.1.min.js"></script>
<script src="__STATIC__/js/select-ui.min.js"></script>

<script>
$(document).ready(function(){	
   $(".select1").uedSelect({
		width : 345		  
   });
   $("#gailvadd").click(function(){
	   $("#gailvgen").before("<li><label>&nbsp;</label><input name='hmin[]' type='text' style='width:80px;' class='dfinput' > 元 -  <input name='hmax[]' type='text' style='width:80px;' class='dfinput' > 元，概率  <input name='hgailv[]' type='text' style='width:80px;' class='dfinput' >&nbsp;&nbsp;第 <input name='hcishu[]' type='text' style='width:80px;' class='dfinput' > 次抽中<i><img src='__STATIC__/Admin/image/t03.png' style='vertical-align:middle; cursor:pointer' onclick='removeFile(this);' /></i></li>");
   });
   $('#monisub').click(function(){
	   //$('#dengdai').show();
	   var options = {
              url: '{:url("ajaxmoni")}',
              type: 'post',
              dataType: 'html',
              data: $("#fadd").serialize(),
              success: function (data) {
				  $('.install').show();
				  $('.install').html(data);
				  $('#dengdai').hide();
              }
            };
        $.ajax(options);
		return false;
   });

});

function removeFile(e){	$(e).parent().parent().remove();}
</script>
<style>
#dengdai{ position:fixed; top:0; left:0; right:0; bottom:0;background-color: rgba(0,0,0,0.5); z-index:99999;display: none;}
#dengdai .loading { width: 80px; height: 40px; margin: 0 auto; margin-top: 20%; }
#dengdai .loading span { display: inline-block; width: 8px; height: 100%; border-radius: 4px; background: lightgreen; -webkit-animation: load 1s ease infinite; }
 @-webkit-keyframes load {  0%, 100% {
 height: 40px;
 background: lightgreen;
}
 50% {
 height: 70px;
 margin: -15px 0;
 background: lightblue;
}
}
#dengdai .loading span:nth-child(2) { -webkit-animation-delay: 0.2s; }
#dengdai .loading span:nth-child(3) { -webkit-animation-delay: 0.4s; }
#dengdai .loading span:nth-child(4) { -webkit-animation-delay: 0.6s; }
#dengdai .loading span:nth-child(5) { -webkit-animation-delay: 0.8s; }
.install { box-shadow: 5px 5px 5px #f7f7f7 inset; border: 1px solid #bdbcbc; width: 530px; height: 200px; overflow: hidden; display: block; overflow-y: scroll; margin-left:123px; font-size: 12px; margin-bottom: 22px; outline: none; display:none; line-height:30px; word-break:break-all; padding:5px; }
</style>
</head>
<body>
<div id="dengdai">
    <div class="loading">
           <span></span>
           <span></span>
           <span></span>
           <span></span>
           <span></span>
    </div>
</div>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li><a href="{:url('Index/center')}">首页</a></li>
    <li><a href="{:url('Hb/show')}">娃娃管理</a></li>
    <li><a href="{:url('Hb/showwawalist')}">娃娃列表</a></li>
    <li>添加/编辑</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>基本信息</span></div>
  <form id="fadd" name="fadd" method="post" action="{:url('hb/save')}" onsubmit="return onCheckAll();">
   <ul class="forminfo">   
   <input type="hidden" id="wawaid" name="id" value="{$hbdata['id']}" />
   <li>
      <label>娃娃编号</label>
      <input id="bianhao" onblur="checkBianhao()" name="hnum" type="text" value="{$hbdata['num']}" class="dfinput" ><i>(整数)<span  id="bianhaotips" style="color:#f00"></span></i>
      </li>
   <li>
      <label>娃娃名称</label>
      <input name="hname" type="text" value="{$hbdata['name']}" class="dfinput" >
      </li>
      <li>
      <label>娃娃价格</label>
      <input name="hprice" type="text" value="{$hbdata['money']}" class="dfinput" ><i>元(整数)</i>
      </li>
      
    <li>
      <label>夹中概率</label>
      
      <input name="hgailv" type="text" maxlength="3" value="{$hbdata['gailv']}"class="dfinput" >
      <i>例如填20,概率则为20%</i>
      </li>
      </li>
      

      <label>&nbsp;</label>
      <input type="submit" name="button" class="btn" value="确认保存" />&nbsp;&nbsp;&nbsp;
    </li>
  </ul>
  </form>
</div>
<div class="install"></div>
<script>	 
	function validateInt(val){
	var reg = /^\+?[0-9][0-9]*$/;

	 return reg.test(val);
	 }
	function isEmpty(str) {

		if(str == undefined || str == null  || str == ""|| str == 'null' || str.length == 0) {
			return true;
		} else {
			return false;
		}
	}
	
	function checkBianhao(){
		var bianhao = $("#bianhao").val();
		$.post("{:url('Hb/checkBianhao')}",{id:$("#wawaid").val(),hnum:bianhao},function(data){
            if(data.data==1){
            	$("#bianhaotips").text("");
            }else{
            	$("#bianhaotips").text("编号已存在");
            }
        },'json');
	}
	
	
	
function onCheckAll(){
	  var t = $('#fadd').serializeArray();
	  var d = {};
	  var res = true;
	  $.each(t, function() {
		  var obj = this;
		  
		  if(obj.name=='hname'){
			  if(isEmpty(obj.value)){
				  res=false;
				  
				  $("input[name='"+obj.name+"']").css("border","solid 1px red");
			  }else{
				  $("input[name='"+obj.name+"']").css("border","solid 1px gray");
			  }
			  
		  }else{
			  
			  if(obj.name!='id'){
				  if(!validateInt(obj.value)||obj.value<=0){
					  res=false;
					  $("input[name='"+obj.name+"']").css("border","solid 1px red");
				  }else{
					  $("input[name='"+obj.name+"']").css("border","solid 1px gray");
				  }
			  }
			  
			  
		  }
		  
		   
	    });
	   return res;
}
</script>
</body>
</html>